package com.webchat.aigc.llm;


import com.webchat.common.exception.AiCallException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Service;

import java.util.List;


@RefreshScope
@Service
public class BasicEmbeddingModel {


    @Value("${llm.embedding.model}")
    private String embedModel;


    public float[] embed(String text) {
        AbstractEmbeddingModel abstractEmbeddingModel = EmbeddingModelFactory.getEmbeddingModel(embedModel);
        try {
            return abstractEmbeddingModel.embed(text);
        } catch (Exception e) {
            throw new AiCallException(String.format("embedding error:%s", e.getMessage()), e);
        }
    }

    public List<float[]> embed(List<String> texts) {
        AbstractEmbeddingModel abstractEmbeddingModel = EmbeddingModelFactory.getEmbeddingModel(embedModel);
        try {
            return abstractEmbeddingModel.embed(texts);
        } catch (Exception e) {
            throw new AiCallException(String.format("embedding error:%s", e.getMessage()), e);
        }
    }
}
